package com.baichuan.zntx.translation;

import com.baichuan.common.translation.annotation.TranslationType;
import com.baichuan.common.translation.constant.TransConstant;
import com.baichuan.common.translation.core.TranslationInterface;
import com.baichuan.zntx.domain.vo.DeviceVo;
import com.baichuan.zntx.service.IDeviceService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author mazhanliang
 */
@Component
@AllArgsConstructor
@TranslationType(type = TransConstant.DEVICE_ID_TO_CODE)
public class DeviceCodeTranslation implements TranslationInterface<String> {
    private final IDeviceService deviceService;
    @Override
    public String translation(Object key, String other) {
        if (key instanceof String id) {
            DeviceVo deviceVo = deviceService.queryById(id);
            if(deviceVo != null){
                return deviceVo.getDeviceId();
            }
            return null;
        }
        return null;
    }
}
